﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OUSMS.AppLogic.DataAccessLayer;
using OUSMS.AppLogic.BusinessLogicLayer;
using System.Web.ModelBinding;
using OUSMS.Helpers;
namespace OUSMS
{
    public partial class GiveFeedbackByExpert : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        // id 参数应与控件上设置的 DataKeyNames 值匹配
        // 或用值提供程序特性装饰，例如 [QueryString]int id
        public Motions motionDetailFormView_GetItem([QueryString("MID")]long id)
        {
            MotionsBLL motionsBLL = new MotionsBLL();
            return motionsBLL.GetMotionsByID(id);
        }

        protected void submitBtn_Click(object sender, EventArgs e)
        {
            try
            {
                UsersBLL userBLL = new UsersBLL();
                Users user = userBLL.GetUserByLoginName(User.Identity.Name);
                MotionReviewerCommentBLL motionReviewerCommentBLL = new MotionReviewerCommentBLL();
                string role = "";
                switch (Request.QueryString["Role"])
                {
                    case "1":
                        role = "评审专家";
                        break;
                    case "2":
                        role = "部门负责人";
                        break;
                    case "3":
                        role = "校领导";
                        break;
                }
                MotionReviewerComments motionReviewerComment = motionReviewerCommentBLL.GetMotionReviewerCommentByMotionIDAndReviewerID(Convert.ToInt64(Request.QueryString["MID"]), user.ID, role);
                TextBox feedbackTxtBox  = motionDetailFormView.FindControl("feedbackTxtBox") as TextBox;
                motionReviewerComment.Comment = feedbackTxtBox.Text.Trim();
                motionReviewerComment.CommentDateTime = DateTime.Now;
                motionReviewerCommentBLL.Save();
                Response.Redirect("WaitForFeedbackMotionList.aspx");
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                Label errorMsgLbl = motionDetailFormView.FindControl("errorMsgLbl") as Label;
                errorMsgLbl.Text = string.Format("信息保存失败，失败原因：{0}", ex.Message);
                errorMsgLbl.Visible = true;
            }
        }

        protected void cancelBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("WaitForFeedbackMotionList.aspx");
        }

        protected void filesGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label indexLbl = e.Row.FindControl("indexLbl") as Label;
                indexLbl.Text = (e.Row.RowIndex + 1).ToString();
            }
        }

        // 返回类型可以更改为 IEnumerable，但是为了支持
        // 分页和排序，必须添加以下参数:
        //     int maximumRows
        //     int startRowIndex
        //     out int totalRowCount
        //     string sortByExpression
        public IQueryable<MotionFiles> filesGridView_GetData([QueryString("MID")]long id)
        {
            MotionFilesBLL motionFilesBLL = new MotionFilesBLL();
            return motionFilesBLL.GetMotionFilesByMotionID(id);
        }
    }
}